package jmine.tec.batch;

import bancosys.tec.exception.LocalizedMessageHolder;
import bancosys.tec.exception.MessageCreator;
import bancosys.tec.exception.MessageCreatorHelper;

/**
 * @author Icaro Kume
 */
public enum JmineTecBatchMessages implements MessageCreator {

    PHASE_ALREADY_EXECUTED(1, "kernel.phase.phaseAlreadyExecuted"),

    PHASE_SATISFIED_DEPENDENCIES(1, "kernel.phase.phaseSatisfiedDependencies"),

    PHASE_STARTED(1, "kernel.phase.phaseStarted"),

    PHASE_FINISHED(1, "kernel.phase.phaseFinished"),

    ERROR_RUNNIG_PHASE(2, "kernel.phase.ErrorRunningPhase"),

    ERROR_RUNNIG_PHASE_RTM(0, "kernel.phase.ErrorRunningPhaseRtm"),

    PHASE_PHASE_FINISHED(1, "kernel.phase.phaseFinished"),

    PHASE_ERROR_FINISHING_PROCESS_ELEMENT(1, "kernel.phase.errorFinishingProcessElement"),

    PHASE_GENERIC_PHASE_EXCEPTION(0, "kernel.phase.genericPhaseException"),

    PHASE_NON_UNIQUE_OBJECT(3, "kernel.phase.nonUniqueObject"),

    PHASE_UNREGISTERED_PHASE(2, "kernel.phase.unregisteredPhase"),

    PHASE_PHASE_MANAGER_NOT_INITIALIZED(0, "kernel.phase.phaseManagerNotInitialized"),

    PHASE_ERROR_RUNNING_PHASE_RTM(0, "kernel.phase.ErrorRunningPhaseRtm"),

    JMINE_TEC_PHASE_CIRCULARITY_DETECTED(1, "jmine.tec.kernel.phase.circularityDetected"),

    PHASE_PHASE_ALREADY_EXECUTED(1, "kernel.phase.phaseAlreadyExecuted"),

    PHASE_ERROR_INSTANTIATING_LISTENER(1, "kernel.phase.errorInstantiatingListener"),

    PHASE_EXEC_PHASE_DOES_NOT_IMPLEMENT_BEFORE_PROCESSING_UNIT_NOTIFICATION(0,
            "kernel.phase.execPhaseDoesNotImplementBeforeProcessingUnitNotification"),

    PHASE_UNABLE_TO_CREATE_PHASE_FOR_ELEMENT(0, "kernel.phase.unableToCreatePhaseForElement"),

    PHASE_ERROR_EXECUTING_TRIGGER(0, "kernel.phase.errorExecutingTrigger"),

    SERVICES_MPHASE_ALREADY_EXISTS(1, "kernel.services.mphaseAlreadyExists"),

    PHASE_RETRIES_EXCEEDED(0, "kernel.phase.retriesExceeded"),

    PHASE_PHASE_NOT_FOUND(1, "kernel.phase.phaseNotFound"),

    EVENT_EVENT_ALREADY_EXECUTED(0, "kernel.event.eventAlreadyExecuted"),

    PHASE_EXEC_PHASE_NOT_FOUND(1, "kernel.phase.execPhaseNotFound"),

    PHASE_BASE_LISTENER_CLASS_NOT_IDENTIFIED(1, "kernel.phase.baseListenerClassNotIdentified"),

    PHASE_ERROR_EXECUTING_TRIGGER_BEFORE(0, "kernel.phase.errorExecutingTriggerBefore"),

    PHASE_UNABLE_TO_FINISH(0, "kernel.phase.unableToFinish"),

    PHASE_ERROR_INVOKING_PHASE_CONSTRUCTOR(1, "kernel.phase.errorInvokingPhaseConstructor"),

    PHASE_LOAD_PHASE_MANAGER_NOT_FOUND(0, "kernel.phase.loadPhaseManagerNotFound"),

    PHASE_BEFORE_PHASE_ERROR(0, "kernel.phase.beforePhaseError"),

    PHASE_ELEMENT_ALREADY_CONTAINS_PHASE(0, "kernel.phase.elementAlreadyContainsPhase"),

    PHASE_ILLEGAL_PHASE_STATE(2, "kernel.phase.illegalPhaseState"),

    SERVICES_MPROCESS_ALREADY_EXISTS(1, "kernel.services.mprocessAlreadyExists"),

    PHASE_MARK_PHASE_WITH_ERROR_UNEXPECTED_EXCEPTION(0, "kernel.phase.markPhaseWithErrorUnexpectedException"),

    PHASE_ERROR_EXECUTING_PHASE(1, "kernel.phase.errorExecutingPhase"),

    PHASE_PHASE_INSTANCE_LOADED_NOTIFIER_NOT_FOUND(1, "kernel.phase.phaseInstanceLoadedNotifierNotFound"),

    PHASE_ERROR_CREATING_PROCESS(2, "kernel.phase.errorCreatingProcess"),

    PHASE_PHASE_STARTED(1, "kernel.phase.phaseStarted"),

    PHASE_GRAPH_ALREADY_INITIALIZED(0, "kernel.phase.graphAlreadyInitialized"),

    PHASE_DEPENDENCY_HAS_DIFFERENT_DATE(2, "kernel.phase.dependencyHasDifferentDate"),

    PHASE_EXECUTION_STATE_MUST_BE_CREATED(0, "kernel.phase.executionStateMustBeCreated"),

    PHASE_UNABLE_TO_MARK_PHASE_WITH_ERROR(1, "kernel.phase.unableToMarkPhaseWithError"),

    PHASE_EXECUTING_LISTENER_CHAIN(1, "kernel.phase.executingListenerChain"),

    PHASE_GENERIC_INTERRUPT_PROCESS(0, "kernel.phase.genericInterruptProcess"),

    PHASE_NO_TRANSACTION_OPENED(0, "kernel.phase.noTransactionOpened"),

    EVENT_UNKOWN_ACTION_MODE(1, "kernel.event.unkownActionMode"),

    PHASE_AFTER_PHASE_ERROR(0, "kernel.phase.afterPhaseError"),

    ISSUE_DEPENDENCY(1, "kernel.issue.dependency"),

    PHASE_ERROR_CREATING_PHASE(1, "kernel.phase.errorCreatingPhase"),

    PHASE_UPDATING_PROCESSING_UNIT_STATUS(1, "kernel.phase.updatingProcessingUnitStatus"),

    PHASE_INVALID_ELEMENT_STATE_CHANGE(0, "kernel.phase.invalidElementStateChange"),

    PHASE_PHASE_TRANSACTION_INCOMPATIBLE_CONTROLLER_OR_JOB(0, "kernel.phase.phaseTransactionIncompatibleControllerOrJob"),

    EVENT_UNABLE_TO_SAVE_EVENT(0, "kernel.event.unableToSaveEvent"),

    PHASE_PHASE_SATISFIED_DEPENDENCIES(1, "kernel.phase.phaseSatisfiedDependencies"),

    PHASE_CONTROLLER_AND_JOB_SHOULD_NOT_SUPPORT_TRANSACTIONS(0, "kernel.phase.controllerAndJobShouldNotSupportTransactions"),

    PHASE_MARK_PHASE_WITH_ERROR(0, "kernel.phase.markPhaseWithError"),

    EVENT_NO_SESSION_BOUND_TO_THREAD_UNABLE_TO_SAVE_EVENT(0, "kernel.event.noSessionBoundToThread.unableToSaveEvent"),

    PHASE_ERROR_EXECUTING_ELEMENT(1, "kernel.phase.errorExecutingElement"),

    PHASE_ERROR_EXECUTING_TRIGGER_AFTER(0, "kernel.phase.errorExecutingTriggerAfter"),

    PHASE_NOTIFICATION_FAILURE_BEFORE(1, "kernel.phase.notificationFailureBefore"),

    PHASE_INSTANTIATION_ERROR(2, "kernel.phase.instantiationError"),

    PHASE_PHASE_ALREADY_INITIALIZED_UNABLE_TO_SET_NEW_EXECUTION_VALUES(0,
            "kernel.phase.phaseAlreadyInitialized.unableToSetNewExecutionValues"),

    PHASE_PHASE_ALREADY_INITIALIZED(0, "kernel.phase.phaseAlreadyInitialized"),

    PHASE_CIRCULARITY_DETECTED(0, "kernel.phase.circularityDetected"),

    PHASE_ELEMENT_HAS_NO_INITIALIZED_EXECUTION(0, "kernel.phase.elementHasNoInitializedExecution"),

    PHASE_PHASE_INSTANCE_NOT_FOUND(2, "kernel.phase.phaseInstanceNotFound"),

    PHASE_STOP_EXECUTION_DUE_TO_PHASE_ERROR(0, "kernel.phase.stopExecutionDueToPhaseError"),

    PHASE_ERROR_RUNNING_PHASE(2, "kernel.phase.ErrorRunningPhase"),

    PHASE_ERROR_CHANGING_PHASE_STATE(1, "kernel.phase.errorChangingPhaseState"),

    PHASE_UNSUPPORTED_LISTENER_TYPE(1, "kernel.phase.unsupportedListenerType"),

    TRANSACTED_PHASE_CANNOT_EXECUTE_IN_ANOTHER_TRANSACTION(0,
            "jmine.tec.kernel.phase.transacted.phase.cannot.execute.in.another.transaction");

    public static final String BUNDLE_NAME = "jmine-tec-batch-messages";

    private final String bundle;

    private final String key;

    private final int nargs;

    /**
     * Cria um message holder de acordo com os argumentos
     * 
     * @param arguments arguments
     * @return message holder
     */
    public LocalizedMessageHolder create(Object... arguments) {
        return MessageCreatorHelper.create(this.bundle, this.key, this.nargs, arguments);
    }

    /**
     * {@inheritDoc}
     */
    public int getExpectedArguments() {
        return this.nargs;
    }

    /**
     * Construtor
     * 
     * @param nargs nargs
     * @param key key
     */
    private JmineTecBatchMessages(int nargs, String key) {
        this(BUNDLE_NAME, key, nargs);
    }

    /**
     * Construtor
     * 
     * @param bundle bundle
     * @param key key
     * @param nargs nargs
     */
    private JmineTecBatchMessages(String bundle, String key, int nargs) {
        this.bundle = bundle;
        this.key = key;
        this.nargs = nargs;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return "MessageCreator: bundle=" + this.bundle + " key=" + this.key;
    }

}
